package sjms.create.singleton;

public class Singleton_3 {
    public static void main(String[] args) {

    }
}

/**
 * 懒汉式——1
 *  优点：实现懒加载
 *  缺点：线程不安全
 *      原因：若有多个线程同时执行到if语句，
 *      则多个线程中的判断都会通过从而产生多个实例
 */

class Singleton3{
    private static Singleton3 instance;

    private Singleton3(){}

    public static Singleton3 getInstance(){
        if(instance == null){
            instance = new Singleton3();
        }
        return instance;
    }
}
